package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressMapper {
    /**
     * 查询当前登录用户的所有地址信息
     * 查询默认地址
     * @param addressBook
     * @return
     */
    List<AddressBook> showAddressBook(AddressBook addressBook);

    /**
     * 新增地址
     * @param addressBook
     */
    void addAddressBook(AddressBook addressBook);


/*    @Update("update address_book set city_code = #{cityCode},city_name = #{cityName},consignee = #{consignee},\n" +
            "                                detail  = #{detail},district_code = #{districtCode},district_name = #{districtName},\n" +
            "                                is_default= #{isDefault}, label= #{label},phone = #{phone},province_code = #{provinceCode},\n" +
            "                                province_name = #{provinceName},sex = #{sex},user_id=#{userId}\n" +
            "        where id = #{id}")
    @Options(useGeneratedKeys = true, keyProperty = "id")*/
    void updateAddressBook(AddressBook addressBook);
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateDefaultAddressBook(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void deleteAddressBook(Long id);
}
